package com.demomaster.quickaccessibility.view.hierarchy;

import android.os.Build;
import android.view.accessibility.AccessibilityNodeInfo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class QuickAccessNode implements Serializable {
    //String contentDescription;
    String mClassName;
    //String text;
    String mPackageName;
    String mViewIdResourceName;
    String mHintText;
    String mTooltipText;
    String mPaneTitle;
    //boolean checked;
    //boolean enabled;
    //boolean selected;
    //boolean clickable;
    //boolean visibleToUser;
    List<QuickAccessNode> childList;
    AccessibilityNodeInfo accessibilityNodeInfo;
    public QuickAccessNode(AccessibilityNodeInfo nodeInfo) {
        this.accessibilityNodeInfo = nodeInfo;
        childList = new ArrayList<>();
        setClassName(accessibilityNodeInfo.getClassName()+"");
        setPackageName(accessibilityNodeInfo.getPackageName()+"");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            setViewIdResourceName(accessibilityNodeInfo.getViewIdResourceName());
        }
        //setContentDescription(accessibilityNodeInfo.getContentDescription()+"");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            setHintText(""+accessibilityNodeInfo.getHintText());
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            setTooltipText(accessibilityNodeInfo.getTooltipText()+"");
            setPaneTitle(accessibilityNodeInfo.getPaneTitle()+"");
        }
        //setVisibleToUser(accessibilityNodeInfo.isVisibleToUser());
        //setClickable(accessibilityNodeInfo.isClickable());
        //setEnabled(accessibilityNodeInfo.isEnabled());
        //setText(accessibilityNodeInfo.getText() + "");
        //setChecked(accessibilityNodeInfo.isChecked());
        //setSelected(accessibilityNodeInfo.isSelected());

        for (int i = 0; i < accessibilityNodeInfo.getChildCount(); i++) {
            AccessibilityNodeInfo child = accessibilityNodeInfo.getChild(i);
            if (child != null) {
                QuickAccessNode viewNodeInfo1 = new QuickAccessNode(child);
                this.addChild(viewNodeInfo1);
            }
        }
    }

    public boolean isChecked() {
        return accessibilityNodeInfo==null?false:accessibilityNodeInfo.isChecked();
    }

//    public void setChecked(boolean checked) {
//        this.checked = checked;
//    }

    public boolean isSelected() {
        return accessibilityNodeInfo==null?false:accessibilityNodeInfo.isSelected();
    }

//    public void setSelected(boolean selected) {
//        this.selected = selected;
//    }

    public AccessibilityNodeInfo getAccessibilityNodeInfo() {
        return accessibilityNodeInfo;
    }

    public void setAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
        this.accessibilityNodeInfo = accessibilityNodeInfo;
    }

    public String getClassName() {
        return mClassName;
    }

    public void setClassName(String mClassName) {
        this.mClassName = mClassName;
    }

    public void addChild(QuickAccessNode viewNodeInfo1) {
        childList.add(viewNodeInfo1);
    }

    public int getChildCount() {
        return childList.size();
    }

    public void setPackageName(String mPackageName) {
        this.mPackageName = mPackageName;
    }

    public String getPackageName() {
        return mPackageName;
    }

    public String getNodePackageName(){
        return accessibilityNodeInfo==null?"":accessibilityNodeInfo.getPackageName()+"";
    }
    public String getViewIdResourceName() {
        return mViewIdResourceName;
    }

    public void setViewIdResourceName(String mViewIdResourceName) {
        this.mViewIdResourceName = mViewIdResourceName;
    }

    public void setHintText(String mHintText) {
        this.mHintText = mHintText;
    }

    public String getHintText() {
        return mHintText;
    }

    public String getPaneTitle() {
        return mPaneTitle;
    }

    public void setPaneTitle(String mPaneTitle) {
        this.mPaneTitle = mPaneTitle;
    }

    public String getTooltipText() {
        return mTooltipText;
    }

    public void setTooltipText(String mTooltipText) {
        this.mTooltipText = mTooltipText;
    }

//    public void setEnabled(boolean enabled) {
//        this.enabled = enabled;
//    }

    public boolean isEnabled() {
        return accessibilityNodeInfo==null?false:accessibilityNodeInfo.isEnabled();
    }

    public boolean isClickable() {
        return accessibilityNodeInfo==null?false:accessibilityNodeInfo.isClickable();
    }

//    public void setClickable(boolean clickable) {
//        this.clickable = clickable;
//    }

    public boolean isVisibleToUser() {
        return accessibilityNodeInfo==null?false:accessibilityNodeInfo.isVisibleToUser();
    }

    public String getContentDescription() {
        //return contentDescription;
        return accessibilityNodeInfo==null?null:(accessibilityNodeInfo.getContentDescription()+"");
    }

//    public void setContentDescription(String contentDescription) {
//        this.contentDescription = contentDescription;
//    }

    public String getText() {
        return accessibilityNodeInfo==null?null:(accessibilityNodeInfo.getText()+"");
    }

//    public void setText(String text) {
//        this.text = text;
//    }

}
